package com.rocky.study.hashmaptest;

/**
 * 异或操作
 *
 * @author rocky
 */
public class XORDemo {

    final static String opt1 = "&";
    final static String opt2 = "^";
    final static String opt3 = "|";
    final static String opt4 = "&";

    public static void main(String[] args) {

        /**
         * 1位数字的运算
         */
        int x1 = 0;
        int r1 = 1;
        String length1 = "一";
        print(x1, r1, opt1, length1);
        print(x1, r1, opt2, length1);
        print(x1, r1, opt3, length1);
        /**
         * 2位数字的运算
         */
        int x2_0 = 00;
        int x2_1 = 01;
        int r2_0 = 10;
        int r2_1 = 11;
        String length2 = "两";
        print(x2_0, x2_1, opt1, length2);
        print(x2_0, r2_0, opt1, length2);
        print(x2_0, r2_1, opt1, length2);
        print(x2_1, r2_0, opt1, length2);
        print(x2_1, r2_1, opt1, length2);
        print(r2_0, r2_1, opt1, length2);
    }

    private static void print(int x, int r, String opt, String length) {
        System.out.println("=======" + length + "位数字的 =======");
        System.out.println(opt + " 运算后的值: " + (x + opt + x) + " = " + calculated(x, x, opt));
        System.out.println(opt + " 运算后的值: " + (x + opt + r) + " = " + calculated(x, r, opt));
        System.out.println(opt + " 运算后的值: " + (r + opt + x) + " = " + calculated(r, x, opt));
        System.out.println(opt + " 运算后的值: " + (r + opt + r) + " = " + calculated(r, r, opt));
    }

    private static int calculated(int x, int y, String opt) {
        if (opt1.equals(opt)) {
            return x & y;
        } else if (opt2.equals(opt)) {
            return x ^ y;
        } else if (opt3.equals(opt)) {
            return x | y;
        }
        return -1;
    }

    private void t(String r1) {
        int x10 = 0000_0000_0000_0000_0000_0000_0000_0000_0000;
        int r10 = 0000_0000_0000_0000_0000_0000_0000_0000_0001;
        int o10 = x10 ^ x10 >>> 16;
        System.out.println("x1异或运算后的值 " + r1);
    }
}
